// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import store from '@/store/index'
import router from './router'
import moment from 'moment'
import echarts from 'echarts'
import ElementUI from 'element-ui'
import VueTree from 'vue-simple-tree'
import CookieUtil from '@/utils/CookieUtil'
import 'babel-polyfill'
import 'element-ui/lib/theme-chalk/index.css'
import '@/assets/iconfont/iconfont.css'
import '@/assets/css/my_custom_style.css'
import '@/assets/bigdata/css/bigdata.css'
import 'font-awesome/css/font-awesome.min.css'
import Watermark from '@/utils/watermark'
// import {getToken} from '@/utils/LocalDataUtil'

// 时间格式化组件 http://momentjs.com/
Vue.prototype.$moment = moment
// echarts插件
Vue.prototype.$echarts = echarts

Vue.use(ElementUI)
Vue.use(VueTree)
Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  if (to.matched.some(m => m.meta.auth)) {
    let token = CookieUtil.getToken()
    // let token = getToken()
    if (!token || token.trim() === '') {
      next({name: 'login', params: {error: ''}})
    } else {
      if (to.fullPath === '/') {
        store.commit('clear_tabs')
      }
    }
  }
  next()
})

router.afterEach((to) => {
  /* 路由发生变化修改页面水印 */
  if (to.path === '/' ||
      to.path === '/login' ||
      // 实战应用去除水印
      to.path === '/people' ||
      to.path === '/house' ||
      to.path === '/matter' ||
      to.path === '/things' ||
      to.path === '/organize' ||
      // 实战大数据去除水印
      to.path === '/zongzhi' ||
      to.path === '/shiyourenkou' ||
      to.path === '/teshurenqun' ||
      to.path === '/qingshaonian' ||
      to.path === '/shehuizhian' ||
      to.path === '/feigongyouzhi' ||
      to.path === '/contradictionAnalysis' ||
      to.path === '/schoolAnalysis' ||
      to.path === '/roadAnalysis' ||
      // 事件分析去除水印
      to.path === '/eventDataAnalysis' ||
      // 防溺管理数据分析去除水印
      to.path === '/waterDataAnalysis') {
    Watermark.rm()
  } else {
    Watermark.set()
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
